be more defensive with deallocation of dynamic memory in tpo.
authortsteven4 <tsteven4@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 3 Aug 2013 11:10:37 +0000 (11:10 +0000)
committertsteven4 <tsteven4@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 3 Aug 2013 11:10:37 +0000 (11:10 +0000)
git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4501 f51c46e8-681c-474f-0cfe-069cfd0219fb

gpsbabel/main.cc
gpsbabel/tpo.cc

index eccf192594d5e92f2d92f20f463522cedb88986c..cd75c613ffa5410177e6500c4bc528da01ddb22f 100644 (file)
@@ -714,6 +714,7 @@ main(int argc, char* argv[])
       ovecs->position_ops.wr_deinit();
     }
     exit(0);
+printf("early\n");
   }
 
 
index 1e599082602fd11a3c5a5d3fa2783131b2ed4518..ae05acb2d69b34dd7d3d51ef67c9e2bf6b2cc568 100644 (file)
@@ -1412,7 +1412,10 @@ static void
 tpo_rd_init(const char* fname)
 {
 
+  // preprare for an attempt to deallocate memory that may or may not get allocated
+  // depending on the options used.
   tpo_index_ptr = 0;
+  tpo_wp_index = NULL;
 
   tpo_file_in = gbfopen_le(fname, "rb", MYNAME);
   tpo_check_version_string();
@@ -1444,9 +1447,13 @@ tpo_rd_deinit(void)
   for (i = 0; i < tpo_index_ptr; i++) {
     waypt_free(tpo_wp_index[i]);
   }
+  tpo_index_ptr = 0;
 
   // Free the index array itself
-  xfree(tpo_wp_index);
+  if (tpo_wp_index) {
+    xfree(tpo_wp_index);
+    tpo_wp_index = NULL;
+  }
 
   gbfclose(tpo_file_in);
 }